<?php

use think\admin\model\SystemSites;
use think\migration\Migrator;

@set_time_limit( 0 );
@ini_set( 'memory_limit', -1 );

/**
* 系统模块初始化
*/

class AddNewSites extends Migrator
 {
    /**
    * 数据库初始化
    * @return void
    */

    public function change()
 {
        $sites = [
            [
                'site_name' => '超科学PT喵',
                'site_url' => 'https://ptneko.com',
                'api_url' => 'https://ptneko.com/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => '悟空问道',
                'site_url' => 'https://wukongwendao.top',
                'api_url' => 'https://wukongwendao.top/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => '兽站',
                'site_url' => 'https://pt.hd4fans.org',
                'api_url' => 'https://pt.hd4fans.org/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => '可鲁',
                'site_url' => 'https://our.kelu.one',
                'api_url' => 'https://our.kelu.one/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => 'kamept',
                'site_url' => 'https://kamept.com',
                'api_url' => 'https://kamept.com/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => '铂金学院',
                'site_url' => 'https://ptchina.org',
                'api_url' => 'https://ptchina.org/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ],
            [
                'site_name' => '超分辨率',
                'site_url' => 'https://srvfi.top',
                'api_url' => 'https://srvfi.top/api/pieces-hash',
                'passkey' => '',
                'download_limit' => 0,
                'upload_limit' => 0,
                'status' => 1,
            ]
        ];

        foreach ( $sites as $site ) {
            $existingSite = SystemSites::mQuery()->db()->where( 'site_url', $site[ 'site_url' ] )->find();

            if ( !$existingSite ) {
                SystemSites::mQuery()->db()->insert( $site );
            } else {
                echo '站点已存在';
            }
        }
    }
}
